package com.neusoft.controller;

import com.neusoft.po.CommonResult;
import com.neusoft.po.Virtualwallet;
import com.neusoft.service.VirtualwalletService;

import java.math.BigDecimal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

//import com.neusoft.po.VirtualWalletTransaction;

@RestController
@RequestMapping("/Virtualwallet")
@RefreshScope
public class VirtualwalletController {

    @Autowired
    private VirtualwalletService virtualwalletService;

    //新增加一个钱包
    @PostMapping("/Virtualwallet/{userId}")
    public CommonResult<Integer> saveVirtualwallet(@PathVariable("userId")String userId){
        int result = virtualwalletService.saveVirtualwallet(userId);
        return new CommonResult(200,"success",result);
    }

    //通过用户ID查询整个钱包,包括现有金额
    @GetMapping("/GetVirtualwalletByUserId/{userId}")
    public CommonResult<Virtualwallet> getVirtualwalletByUserId(@PathVariable("userId") String userId){
        Virtualwallet vir = virtualwalletService.getVirtualwalletByUserId(userId);
        CommonResult commonResult = new CommonResult(200,"success",vir);
        return commonResult;
    }

    //根据用户ID给钱包充值
    @PutMapping("/RechargeByUserId/{userId}/{add_balance}")
    public CommonResult<Integer> rechargeByUserId(@PathVariable("userId") String userId,@PathVariable("add_balance") BigDecimal add_balance){
        int result = virtualwalletService.rechargeByUserId(userId,add_balance);
        CommonResult commonResult = new CommonResult(200,"success",result);
        return commonResult;
    }

    //跟据用户ID提现
    @PutMapping("/PayoutByUserId/{userId}/{sub_balance}")
    public CommonResult<Integer> payoutByUserId(@PathVariable("userId") String userId,@PathVariable("sub_balance") BigDecimal sub_balance) {
        int result=virtualwalletService.payoutByUserId(userId, sub_balance);
        return new CommonResult(200,"success",result);
    }
}
